home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 6 / clmfeb85.zip / ARGLOOP.H < prev    next >
Text File  |  1988-07-25  |  3KB  |  102 lines

  1. /* argloop.h: @(#) Begining of argument loop, see argparse.h */
  2. /* by Alexander B. Abacus */
  3.  
  4.   a0.keysTerminated = 0;
  5.   a0.nextPositional = 1;
  6.   a0.argIndex = 1;
  7.  
  8.   if ( ( a0.argVector[1][0] == a0.keyTrigger )
  9.   &&   ( a0.argVector[1][1] == '!'           ) )
  10.   {
  11.     a0.textPointer = & a0.argVector[1][1];
  12. #ifdef Debug
  13.       /* if not followed by characters, debug all levels */
  14.       if ( (* (a0.textPointer + 1)) == '\0' ) debug[0] = (char) 127;
  15.  
  16.       /* if followed by characters, select debugging levels */
  17.       while ( (* ++a0.textPointer) != '\0' )
  18.       { /* for all characters following -! */
  19.         if ((* a0.textPointer) < 128) ++debug[* a0.textPointer];
  20.       } /* for all characters following -! */
  21. #else ! defined Debug
  22.       fprintf
  23.       ( stderr
  24.       , " Compiled without debugging code. Option -! ineffective.\n"
  25.       );
  26. #endif Debug
  27.     ++a0.argIndex;
  28.   }
  29.  
  30.   for ( (a0.argIndex); (a0.argIndex < a0.argc); (++a0.argIndex) )
  31.   { /* for all arguments */
  32. #ifdef DriverH
  33.     fprintf ( stderr, "Word %d \"%s\".\n", a0.argIndex, a0.argVector[a0.argIndex] );
  34. #endif DriverH
  35.  
  36.     if ( ( a0.argVector[a0.argIndex][0] != a0.keyTrigger )
  37.     ||   ( a0.keysTerminated != 0                        )
  38.     ||   ( a0.argVector[a0.argIndex][1] == '\0'          ) )
  39.     { /* not a key: bubble up positional arguments */
  40.       if
  41.       (  ( a0.maxPositionals  >= 0 )
  42.       && ( a0.nextPositional > a0.maxPositionals )
  43.       )
  44.       { /* if(too many positionals) */
  45.         fprintf
  46.         ( stderr
  47.         , " Stop. Maximum %d positional arguments, excess at \"%s\".\n"
  48.         , a0.maxPositionals
  49.         , a0.argVector[a0.argIndex]
  50.         );
  51.         ArgTutor( a0.tutorial );
  52.       } /* if(too many positionals) */
  53.       a0.keysTerminated |= a0.keysLeading;
  54.       a0.argVector[a0.nextPositional] = a0.argVector[a0.argIndex];
  55.       /* (void) */ (*a0.ptrFunction) ( '\0', a0.argVector[a0.nextPositional] );
  56.       ++a0.nextPositional;
  57.     }
  58.     else /* it is a key */
  59.     {
  60.       a0.charIndex = 0;
  61.       a0.keyPointer = & a0.argVector[a0.argIndex][0];
  62.       do
  63.       { /* for all characters in an argument */
  64.         ++a0.charIndex;
  65.         ++a0.keyPointer;
  66.         if ( (*a0.keyPointer) == '\0' ) { break; } /* from do ... while */
  67. #ifdef DriverH
  68.         fprintf( stderr, "Remaining argument: \"%s\".\n", a0.keyPointer );
  69. #endif DriverH
  70.  
  71.         if ( a0.keyPointer[0] == a0.keyTrigger )
  72.         {
  73.           if ( a0.charIndex != 1 )
  74.           {
  75.             fprintf
  76.             ( stderr
  77.             , " Stop. Terminator of keys must be alone: \"%s\".\n"
  78.             , a0.argVector[a0.argIndex]
  79.             );
  80.             ArgTutor( a0.tutorial );
  81.           }
  82.           if ( a0.keyPointer[1] != '\0' )
  83.           {
  84.             fprintf
  85.             ( stderr
  86.             , " Stop. Terminator of keys followed by: \"%s\".\n"
  87.             , a0.argVector[a0.argIndex]
  88.             );
  89.             ArgTutor( a0.tutorial );
  90.           }
  91.           a0.keysTerminated = 1;
  92.         }
  93.         else
  94.         {
  95.           switch ( a0.keyPointer[0] )
  96.           {
  97.           case '?':
  98.             ArgTutor( a0.tutorial );
  99.             exit( a0.argc != 2);
  100.  
  101. /* argloop.h: End of file. */
  102.